home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 131 / XENIATGM131.iso / Shareware / openOffice.org 641 / Windows / f_0017 / Layouter.xba < prev    next >
Extensible Markup Language  |  2001-11-22  |  11KB  |  349 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3.  <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Layouter" script:language="StarBasic">Option Explicit
  4.  
  5. Public oProgressbar as Object
  6. Public ProgressValue as Integer
  7. Public oDocument as Object
  8. Public oController as Object
  9. Public oForm as Object
  10. Public oDrawPage as Object
  11. Public oPageStyle as Object
  12.  
  13. Public nMaxColRightX as Long
  14. Public nMaxTCWidth as Long
  15. Public nMaxRowRightX as Long
  16. Public nMaxRowY as Long
  17. Public nSecMaxRowY as Long
  18. Public MaxIndex as Integer
  19. Public CurIndex as Integer
  20.  
  21. Public Const cVertDistance = 200
  22. Public Const cHoriDistance = 300
  23.  
  24. Public nPageWidth as Long
  25. Public nPageHeight as Long
  26. Public nFormWidth as Long
  27. Public nFormHeight as Long
  28. Public nMaxHoriPos as Long
  29. Public nMaxVertPos as Long
  30.  
  31. Public CONST SBALIGNLEFT = 0
  32. Public CONST SBALIGNRIGHT = 2
  33.  
  34. Public Const SBNOBORDER = 0
  35. Public Const SB3DBORDER = 1
  36. Public Const SBSIMPLEBORDER = 2
  37.  
  38. Public CurArrangement as Integer
  39. Public CurBorderType as Integer
  40. Public CurAlignmode as Integer
  41.  
  42. Public OldAlignMode as Integer
  43. Public OldBorderType as Integer
  44. Public OldArrangement as Integer
  45.  
  46. Public Const cColumnarLeft = 1
  47. Public Const cColumnarTop = 2
  48. Public Const cTabled = 3
  49. Public Const cLeftJustified = 4
  50. Public Const cTopJustified = 5
  51.  
  52. Public Const cXOffset = 1000
  53. Public Const cYOffset = 700
  54. ' This is the viewed space that we lose because of the symbol bars
  55. Public Const cSymbolMargin = 2000
  56. Public Const MaxFieldIndex = 200
  57.    
  58. Public Const cControlCollectionCount = 9
  59. Public Const cLabel         = 1
  60. Public Const cTextBox         = 2
  61. Public Const cCheckBox         = 3
  62. Public Const cDateBox         = 4
  63. Public Const cTimeBox         = 5
  64. Public Const cNumericBox     = 6
  65. Public Const cCurrencyBox     = 7
  66. Public Const cGridControl    = 8
  67. Public Const cImageControl    = 9
  68.  
  69. Public Styles(8, 50) as String
  70. Public FieldMetaValues(MaxFieldIndex,3)
  71. ' Description of this List:
  72. ' FieldMetaValues(0-MaxFieldIndex,0) (Datafieldtype)
  73. ' FieldMetaValues(0-MaxFieldIndex,1) (Datafieldlength)
  74. ' FieldMetaValues(0-MaxFieldIndex,2) (ControlType eg. cLabel, cTextbox usw.)
  75.  
  76. Public FieldNames(MaxFieldIndex) as string
  77. Public oModelService(cControlCollectionCount) as String
  78. Public oGridModel as Object
  79.  
  80.  
  81. Function InsertControl(oContainer as Object, oControlObject as object, aPoint as Object, aSize as Object)
  82. Dim oShape as object
  83.     oShape = oDocument.CreateInstance ("com.sun.star.drawing.ControlShape")
  84.     oShape.Size = aSize
  85.     oShape.Position = aPoint
  86.     oShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
  87.     oShape.control = oControlObject
  88.     oContainer.Add(oShape)
  89.     InsertControl() = oShape
  90. End Function
  91.  
  92.  
  93. Function ArrangeControls()
  94. Dim oShape as Object
  95. Dim i as Integer
  96.     oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
  97.     oProgressbar.Start("", MaxIndex)
  98.     If oDBForm.HasbyName("Grid1") Then
  99.         oDBForm.GetByName("Grid1").Dispose
  100.     End If
  101.     ToggleLayoutPage(False)
  102.     Select Case CurArrangement
  103.         Case cTabled
  104.             PositionGridControl(MaxIndex)
  105.         Case Else
  106.             PositionControls(MaxIndex)
  107.     End Select
  108.     ToggleLayoutPage(True)
  109.     oProgressbar.End
  110. End Function
  111.  
  112.  
  113. Sub OpenFormDocument()
  114. Dim NoArgs() as new com.sun.star.beans.PropertyValue
  115. Dim oViewSettings as Object
  116.     oDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter", "_blank", 0, NoArgs())
  117.     oProgressbar = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator()
  118.     oProgressbar.Start("", 100)
  119.     oDocument.ApplyFormDesignMode = False
  120.     oController = oDocument.GetCurrentController
  121.     oViewSettings = oDocument.CurrentController.ViewSettings
  122.     oViewSettings.ShowTableBoundaries = False
  123.     oViewSettings.ShowTextBoundaries = False
  124.     oViewSettings.ShowOnlineLayout = True
  125.     oViewSettings.ShowHoriRuler = True
  126.     oDrawPage = oDocument.DrawPage
  127.     oPageStyle = oDocument.StyleFamilies.GetByName("PageStyles").GetByName("Standard")
  128. End Sub
  129.  
  130.  
  131. Sub    InitializeLabelValues()
  132. Dim oLabelModel as Object
  133. Dim oTBModel as Object
  134. Dim oLabelShape as Object
  135. Dim oTBShape as Object
  136. Dim aTBSize As New com.sun.star.awt.Size
  137. Dim aLabelSize As New com.sun.star.awt.Size
  138. Dim aPoint As New com.sun.star.awt.Point
  139. Dim oLocControl as Object
  140. Dim oLocPeer as Object
  141.     oLabelModel =  CreateUnoService("com.sun.star.form.component.FixedText")
  142.     oTBModel =  CreateUnoService("com.sun.star.form.component.TextField")
  143.     Set oLabelShape = InsertControl(oDrawPage, oLabelModel, aPoint, aSize)
  144.     Set oTBShape = InsertControl(oDrawPage, oTBModel, aPoint, aSize)
  145.     oLocPeer = oController.GetControl(oLabelModel).Peer
  146.     XPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterX
  147.     YPixelFactor = 100000/oLocPeer.GetInfo.PixelPerMeterY
  148.     aLabelSize = GetPeerSize(oLabelModel, oLocControl, "The quick brown fox...")
  149.     nTCHeight = (aLabelSize.Height+1) * YPixelFactor
  150.     aTBSize = GetPeerSize(oTBModel, oLocControl, "The quick brown fox...")
  151.     nDBRefHeight = (aTBSize.Height+1) * YPixelFactor
  152.     LabelDiffHeight = Clng((nDBRefHeight - nTCHeight)/2)
  153.     oDrawPage.Remove(oLabelShape)
  154.     oDrawPage.Remove(oTBShape)
  155. End Sub
  156.  
  157.  
  158. Sub ConfigurePageStyle()
  159. Dim aPageSize As New com.sun.star.awt.Size
  160. Dim aSize As New com.sun.star.awt.Size
  161.     oPageStyle.IsLandscape = True
  162.     aPageSize = oPageStyle.Size
  163.     nPageWidth = aPageSize.Width
  164.     nPageHeight = aPageSize.Height
  165.     aSize.Width = nPageHeight
  166.     aSize.Height = nPageWidth
  167.     oPageStyle.Size = aSize
  168.     nPageWidth = nPageHeight
  169.     nPageHeight = oPageStyle.Size.Height
  170.     nFormWidth = nPageWidth - oPageStyle.RightMargin - oPageStyle.LeftMargin - 2 * cXOffset
  171.     nFormHeight = nPageHeight - oPageStyle.TopMargin - oPageStyle.BottomMargin - 2 * cYOffset - cSymbolMargin
  172. End Sub
  173.  
  174.  
  175. ' Modify the Borders of the Controls
  176. Sub ChangeBorderLayouts(oEvent as Object)
  177. Dim oModel as Object
  178. Dim i as Integer
  179. Dim oCurModel as Object
  180. Dim sLocText as String
  181.     If Not bDebug Then
  182.         On Local Error GoTo WIZARDERROR
  183.     End If
  184.  
  185.     oModel = oEvent.Source.Model
  186.     SwitchBorderMode(Val(Right(oModel.Name,1)))
  187.     ToggleLayoutPage(False)
  188.  
  189. ' Todo: Auch unsichtbare Controls m├╝ssen eine neue Border bekommen
  190. ' Am besten wird hierbei das dynamische Array oDBShapeList() abgegriffen
  191.     If CurArrangement = cTabled Then
  192.         oGridModel.Border = CurBorderType
  193.     Else
  194.         If OldBorderType <> CurBorderType Then
  195.             For i = 0 To MaxIndex
  196.                 oDBModelList(i).Border = CurBorderType
  197.             Next i
  198.         End If
  199.     End If
  200. WIZARDERROR:
  201.     If Err <> 0 Then    
  202.         Msgbox(sMsgErrMsg, 16, GetProductName())
  203.         Resume LOCERROR
  204.         LOCERROR:        
  205.     End If
  206.     ToggleLayoutPage(True)
  207. End Sub
  208.  
  209.  
  210. Sub ChangeLabelAlignments(oEvent as Object)
  211. Dim i as Integer
  212. Dim oSize as New com.sun.star.awt.Size
  213. Dim oModel as Object
  214.     If Not bDebug Then
  215.         On Local Error GoTo WIZARDERROR
  216.     End If
  217.     oModel = oEvent.Source.Model
  218.     SwitchAlignMode(Val(Right(oModel.Name,1)))
  219.     ToggleLayoutPage(False)
  220.     If OldAlignMode <> CurAlignMode Then
  221.         For i = 0 To MaxIndex
  222.             oTCShapeList(i).GetControl.Align = CurAlignmode
  223.         Next i
  224.     End If
  225.     If CurAlignmode = com.sun.star.awt.TextAlign.RIGHT Then
  226.         For i = 0 To Ubound(oTCShapeList())
  227.             oSize = oTCShapeList(i).Size
  228.             oSize.Width = oDBShapeList(i).Position.X - oTCShapeList(i).Position.X - cHoriDistance
  229.             oTCShapeList(i).Size = oSize
  230.         Next i
  231.     End If
  232.  
  233. WIZARDERROR:
  234.     If Err <> 0 Then    
  235.         Msgbox(sMsgErrMsg, 16, GetProductName())
  236.         Resume LOCERROR
  237.         LOCERROR:        
  238.     End If
  239.     ToggleLayoutPage(True)
  240. End Sub
  241.  
  242.  
  243. Sub ChangeArrangemode(oEvent as Object)
  244. Dim oModel as Object
  245.     If Not bDebug Then
  246.         On Local Error GoTo WIZARDERROR
  247.     End If
  248.     oModel = oEvent.Source.Model
  249.     SwitchArrangementButtons(Val(Right(oModel.Name,1)))
  250.     oModel.State = 1
  251.     DlgFormDB.GetControl("cmdArrange" & OldArrangement).Model.State = 0
  252.     If CurArrangement <> OldArrangement Then
  253.         ArrangeControls()
  254.         Select Case CurArrangement
  255.             Case cTabled
  256.                 ToggleBorderGroup(False)
  257.                 ToggleAlignGroup(False)
  258.             Case Else ' cColumnarTop,cLeftJustified, cTopJustified
  259.                 ToggleAlignGroup(CurArrangement = cColumnarLeft)
  260.                 If CurArrangement = cColumnarTop Then
  261.                     If CurAlignMode = com.sun.star.awt.TextAlign.RIGHT Then
  262.                         oDialogModel.optAlign0.State = 1
  263.                         CurAlignMode = com.sun.star.awt.TextAlign.LEFT
  264.                         OldAlignMode = com.sun.star.awt.TextAlign.RIGHT
  265.                     End If
  266.                 End If
  267.                 ControlCaptionstoStandardLayout()
  268.                 oDBForm.Load
  269.         End Select
  270.     End If
  271. WIZARDERROR:
  272.     If Err <> 0 Then    
  273.         Msgbox(sMsgErrMsg, 16, GetProductName())
  274.         Resume LOCERROR
  275.         LOCERROR:        
  276.     End If
  277. End Sub
  278.  
  279.  
  280. Sub    ToggleBorderGroup(bDoEnable as Boolean)
  281.     With oDialogModel
  282.         .hlnBorderLayout.Enabled = bDoEnable
  283.         .optBorder0.Enabled = bDoEnable         ' 0: No border
  284.         .optBorder1.Enabled = bDoEnable        ' 1: 3D border
  285.         .optBorder2.Enabled = bDoEnable        ' 2: simple border
  286.     End With
  287. End Sub
  288.  
  289.  
  290. Sub    ToggleAlignGroup(ByVal bDoEnable as Boolean)
  291.     With oDialogModel
  292.         If bDoEnable Then
  293.             bDoEnable = CurArrangement = cColumnarLeft
  294.         End If
  295.         .hlnAlign.Enabled = bDoEnable
  296.         .optAlign0.Enabled = bDoEnable
  297.         .optAlign2.Enabled = bDoEnable
  298.     End With
  299. End Sub
  300.  
  301.  
  302. Sub ToggleLayoutPage(bDoEnable as Boolean, Optional FocusControlName as String)
  303.     oDialogModel.Enabled = bDoEnable
  304.     If bDoEnable Then
  305.         oDocument.UnlockControllers()
  306.         ToggleOptionButtons(oDialogModel,(bWithBackGraphic = True))
  307.         ToggleAlignGroup(bDoEnable)
  308.         ToggleBorderGroup(bDoEnable)
  309.     Else
  310.         oDocument.LockControllers()    
  311.     End If
  312.     If Not IsMissing(FocusControlName) Then
  313.         DlgFormDB.GetControl(FocusControlName).SetFocus()
  314.     End If    
  315. End Sub
  316.  
  317.  
  318. Sub DestroyControlShapes(oDrawPage as Object)
  319. Dim i as Integer
  320. Dim oShape as Object
  321.     For i = oDrawPage.Count-1 To 0 Step -1
  322.         oShape = oDrawPage.GetByIndex(i)
  323.         If oShape.ShapeType = "com.sun.star.drawing.ControlShape" Then
  324.             oShape.Dispose()
  325.         End If
  326.     Next i
  327. End Sub
  328.  
  329.  
  330. Sub SwitchArrangementButtons(ByVal LocArrangement as Integer)
  331.     OldArrangement = CurArrangement
  332.     CurArrangement = LocArrangement
  333.     If OldArrangement <> 0 Then
  334.         DlgFormDB.GetControl("cmdArrange" & OldArrangement).Model.State = 0
  335.     End If
  336.     DlgFormDB.GetControl("cmdArrange" & CurArrangement).Model.State = 1
  337. End Sub
  338.  
  339.  
  340. Sub SwitchBorderMode(ByVal LocBorderType as Integer)
  341.     OldBorderType = CurBorderType
  342.     CurBorderType = LocBorderType
  343. End Sub
  344.  
  345.  
  346. Sub SwitchAlignMode(ByVal LocAlignMode as Integer)
  347.     OldAlignMode = CurAlignMode
  348.     CurAlignMode = LocAlignMode
  349. End Sub</script:module>